package experiment_03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class SocketHandler implements Runnable {

	private Socket socket;
	private char[] line;

	public SocketHandler(Socket socket) {
		this.socket=socket;
	}

	@Override
	public void run() {
		 
		try {
			InputStreamReader reader = new InputStreamReader(socket.getInputStream());
			BufferedReader br = new BufferedReader(reader);
			PrintWriter writer = new PrintWriter(socket.getOutputStream());
			String client="<"+socket.getInetAddress().toString()+":"+socket.getPort()+">";
			String request=br.readLine();
			System.out.println(client+" say:"+request);
			String line=client+"Hello,too!!!";
			writer.println(line);
			writer.flush();
			writer.close();
			br.close();
			socket.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  
		
	}

}
